package com.thinkfit.jy.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.common.lib.bean.VideoListBean;
import com.thinkfit.jy.R;
import com.thinkfit.jy.bean.CreateTrainItemBean;
import com.thinkfit.jy.utils.ImageLoadUtils;
import com.thinkfit.jy.utils.Utils;

import org.jetbrains.annotations.NotNull;

public class CreateTrainPlanAdapter extends BaseQuickAdapter<CreateTrainItemBean, BaseViewHolder> {

    private Context mContext;
    OnClick onClick;

    public CreateTrainPlanAdapter(Context context) {
        super(R.layout.item_create_train);
        mContext = context;
    }


    @Override
    protected void convert(@NotNull BaseViewHolder helper, CreateTrainItemBean bean) {
        TextView tvSectionTime = helper.getView(R.id.tv_section_time);
        TextView tvSectionSpeed = helper.getView(R.id.tv_section_speed);
        TextView tvSectionSlop = helper.getView(R.id.tv_section_slop);
        ImageView ivDelete = helper.getView(R.id.iv_delete);
        if(getData().size() > 0){
            ivDelete.setVisibility(View.VISIBLE);
        }

        if(!TextUtils.isEmpty(bean.getTime())){
            tvSectionTime.setText(bean.getTime()+getContext().getResources().getString(R.string.app_min_small));
        }else {
            tvSectionTime.setText("");
        }
        if(!TextUtils.isEmpty(bean.getSlop())){
            tvSectionSlop.setText(bean.getSlop()+"%");
        }else {
            tvSectionSlop.setText("");
        }
        if(!TextUtils.isEmpty(bean.getSpeed())){
            Integer integer = Integer.valueOf(bean.getSpeed());
            tvSectionSpeed.setText(Utils.getNewFloat(integer/10f)+getContext().getResources().getString(R.string.app_km_h));
        }else {
            tvSectionSpeed.setText("");
        }


        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                remove(bean);
            }
        });
        tvSectionTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClick.onClick(v,getItemPosition(bean),bean);
            }
        });
        tvSectionSpeed.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onClick.onClick(v,getItemPosition(bean),bean);
            }
        });
        tvSectionSlop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClick.onClick(v,getItemPosition(bean),bean);
            }
        });

    }
    public void setOnClick(OnClick onClick){
        this.onClick = onClick;
    }

    public interface OnClick{
        void onClick(View view,int position,CreateTrainItemBean bean);
    }
}
